import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    gwcList: [
    //   {
    //   "id": "",
    //   "pic": "",
    //   "name": "",
    //   "minPrice": "",
    //   "num": "",
    //   "isbuy": true,
    // }
  ]
  },
  getters: {

  },
  mutations: {
    add(state, obj) {
      obj.buy = true
      var index = state.gwcList.findIndex(v => v.id == obj.id)
      if (index == -1) {
        obj.num = 1
        state.gwcList.push(obj)
      } else {
        state.gwcList[index].num += 1
      }
      state.gwcList.push(obj)
      console.log(state.gwcList)
    }
  },
  actions: {},
  modules: {}
})